#include <iostream>
#include <cluster.h>

#include <cmath>

#include <sds/sfile.h>
#include <sds/sdataset.h>
#include <sds/sdataview.h>

using namespace sds;

int main(int argc, const char *argv[]) {

  SFile clufile(argv[1]);
  SDataView<unsigned char> clu = 
    clufile.getDataset(0).getDataView<unsigned char>();

  std::vector<SInteger> size = clu.getSize();

  std::vector<double> clusters(256, 0);

  for (int i = 0; i < size[0]; ++i) {
    for (int j = 0; j < size[1]; ++j) {
      ++clusters[clu[i][j]];
    }
  }

  double num = 0, sum = 0, sqr = 0;
  
  for (int i = 1; i < 256; ++i) {
    if (clusters[i] != 0) {
      ++num;
      sum += clusters[i];
      sqr += clusters[i] * clusters[i];
    }
  }

  double mean = sum / num;
  double dev = std::sqrt(sqr / (num - 1) - mean * sum / (num - 1));
  

  std::cout << "Nem klaszterezett pontok: " << clusters[0] << std::endl;
  std::cout << "Klaszterek szama: " << num << std::endl;
  std::cout << "Klaszter meret atlaga: " << mean << std::endl;
  std::cout << "Klaszter meret szorasa: " << dev << std::endl;
  
  
  return 0;
}
